home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / CDE / I-N / MCM-InitShare.cpt / cdev.p < prev    next >
Text File  |  1988-06-23  |  5KB  |  217 lines

  1.  
  2. UNIT RunINITs;
  3.  
  4.  
  5. {-----}  INTERFACE  {---------------------------------------------------------}
  6.  
  7. USES
  8.     {$LOAD MQOTP.dump}
  9.     Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf;
  10.  
  11.  
  12. FUNCTION Main (message, item, numItems, CPanelID: INTEGER;
  13.                     theEvent: EventRecord; cdevValue: LONGINT;
  14.                     CPDialog: DialogPtr): LONGINT;
  15.  
  16.  
  17. {-----}  IMPLEMENTATION  {----------------------------------------------------}
  18.  
  19. TYPE
  20.     cdevStorRec    =    RECORD
  21.                             button    :    INTEGER;            { our number + offset }
  22.                             pathRsrc    :    StringHandle;    { handle to our resource }
  23.                             modified    :    BOOLEAN;            { flag }
  24.                             pathStr    :    STR255;            { current path name }
  25.                             pathItem    :    Handle;            { item handle }
  26.                             pathRect    :    Rect;                { item rect }
  27.                         END;
  28.     cdevStorPtr    =     ^cdevStorRec;
  29.     cdevStorHdl    =     ^cdevStorPtr;
  30.  
  31.  
  32. FUNCTION DoInit (CPDialog: DialogPtr; numItems: INTEGER): LONGINT; FORWARD;
  33.  
  34. PROCEDURE DoHit (storHdl: cdevStorHdl; item: INTEGER); FORWARD;
  35.  
  36. PROCEDURE DoClose (storHdl: cdevStorHdl); FORWARD;
  37.  
  38.  
  39. {-----------------------------------------------------------------------------}
  40.  
  41. FUNCTION Main (message, item, numItems, CPanelID: INTEGER;
  42.                     theEvent: EventRecord; cdevValue: LONGINT;
  43.                     CPDialog: DialogPtr): LONGINT;
  44.  
  45.     BEGIN
  46.  
  47.         IF ((cdevValue < -1) OR (cdevValue > 1)) THEN
  48.             CASE message OF
  49.                 initDev:
  50.                     cdevValue := DoInit (CPDialog, numItems);
  51.                 hitDev:
  52.                     DoHit (cdevStorHdl(cdevValue), item);
  53.                 closeDev:
  54.                     BEGIN
  55.                         DoClose (cdevStorHdl(cdevValue));
  56.                         cdevValue := 0;
  57.                     END;
  58.                 OTHERWISE
  59.             END;
  60.  
  61.         Main := cdevValue;
  62.  
  63.     END;
  64.  
  65.  
  66. {-----------------------------------------------------------------------------}
  67.  
  68. { GetWDPathName -- return path name of working directory }
  69. FUNCTION GetWDPathName (wdRefNum: INTEGER): Str255;
  70.  
  71. { The low-level File Manager routine PBGetCatInfo uses the Catalog
  72.   Info Parameter Block Record (CInfoPBRec) for transferring
  73.   information. The input parameters are:
  74.   ioCompletion    -- completion routine,
  75.   ioNamePtr        -- path name,
  76.   ioVRefNum        -- working directory reference number,
  77.   ioDrDirID        -- directory ID or file number,
  78.   ioFDirIndex    -- index.
  79.   We use a synchronous call, which causes ioCompletion to be set to
  80.   NIL by the File Manager.
  81.   If both ioVRefNum and ioDrDirID are provided, ioDrDirID is used to
  82.   identify the directory on the volume indicated by ioVRefNum. If
  83.   ioDrDirID is set to zero, ioVRefNum is used.
  84.   A negative value of ioFDirIndex causes the File Manager to ignore
  85.   ioNamePtr.
  86.   The relevant output parameters are:
  87.   ioNamePtr        -- path name,
  88.   ioDrDirID        -- directory ID or file number,
  89.   ioDrParID        -- parent directory ID.
  90.   If ioDrDirID is zero on input, it is set to the directory ID of
  91.   the working directory on output. If ioDrDirID is nonzero on input
  92.   its value does not change.
  93. }
  94.  
  95.     VAR
  96.         params        : CInfoPBRec;
  97.         theErr        : OSErr;
  98.         tempName        : Str255;
  99.         pathName        : Str255;
  100.     
  101.     BEGIN
  102.  
  103.         pathName := '';
  104.         WITH params DO BEGIN
  105.             ioVRefNum := wdRefNum;
  106.             ioFDirIndex := -1;        { don't use ioNamePtr for input }
  107.             ioNamePtr := @tempName;
  108.             ioDrDirID := 0;            { use working directory reference number
  109.                                               on the first pass through the loop }
  110.         END;
  111.         REPEAT
  112.             params.ioDrDirID := params.ioDrParID;
  113.             theErr := PBGetCatInfo (@params, FALSE);
  114.             pathName := ConCat (tempName, ':', pathName);
  115.         UNTIL (params.ioDrDirID = 2);
  116.         GetWDPathName := pathName;
  117.  
  118.     END;
  119.  
  120.  
  121. {-----------------------------------------------------------------------------}
  122.  
  123. FUNCTION DoInit (CPDialog: DialogPtr; numItems: INTEGER): LONGINT;
  124.  
  125.     CONST
  126.         versItem        = 1;
  127.         infoItem        = 2;
  128.         nameItem        = 3;
  129.         changeItem    = 4;
  130.         pathStrID    = -4048;
  131.  
  132.     VAR
  133.         tempHdl        : StringHandle;
  134.         storHdl        : cdevStorHdl;
  135.         itemType        : INTEGER;
  136.  
  137.     BEGIN
  138.  
  139.         tempHdl := GetString (pathStrID);
  140.         IF (tempHdl = NIL) THEN BEGIN
  141.             IF (ResError = resNotFound) THEN
  142.                 DoInit := cdevResErr
  143.             ELSE
  144.                 DoInit := cdevMemErr;
  145.             EXIT (DoInit);
  146.         END;
  147.  
  148.         storHdl := cdevStorHdl (NewHandle (SIZEOF (cdevStorRec)));
  149.         IF (storHdl = NIL) THEN BEGIN
  150.             DoInit := cdevMemErr;
  151.             EXIT (DoInit);
  152.         END;
  153.  
  154.         WITH storHdl^^ DO BEGIN
  155.             button := numItems + changeItem;
  156.             pathRsrc := tempHdl;
  157.             modified := FALSE;
  158.             pathStr := pathRsrc^^;
  159.             GetDItem (CPDialog, numItems+nameItem, itemType, pathItem, pathRect);
  160.             SetIText (pathItem, pathStr);
  161.         END;
  162.  
  163.         DoInit := ORD4 (storHdl);
  164.  
  165.     END;
  166.  
  167.  
  168. {-----------------------------------------------------------------------------}
  169.  
  170. PROCEDURE DoHit (storHdl: cdevStorHdl; item: INTEGER);
  171.  
  172.     VAR
  173.         thePoint: Point;
  174.         typeList: SFTypeList;
  175.         reply: SFReply;
  176.  
  177.     BEGIN
  178.  
  179.         WITH storHdl^^ DO
  180.             IF (item = button) THEN BEGIN
  181.                 thePoint.v := 100;
  182.                 thePoint.h := 100;
  183.                 SFGetFile (thePoint, '', NIL, -1, typeList, NIL, reply);
  184.                 IF reply.good THEN BEGIN
  185.                     pathStr := GetWDPathName (reply.vRefNum);
  186.                     SetIText (pathItem, pathStr);
  187.                     InvalRect (pathRect);
  188.                     modified := TRUE;
  189.                 END;
  190.             END;
  191.  
  192.     END;
  193.  
  194.  
  195. {-----------------------------------------------------------------------------}
  196.  
  197. PROCEDURE DoClose (storHdl: cdevStorHdl);
  198.  
  199.     BEGIN
  200.  
  201.         IF (storHdl <> NIL) THEN BEGIN
  202.             WITH storHdl^^ DO
  203.                 IF (modified) THEN BEGIN
  204.                     HNoPurge (Handle(pathRsrc));
  205.                     SetString (pathRsrc, pathStr);
  206.                     ChangedResource (Handle(pathRsrc));
  207.                     WriteResource (Handle(pathRsrc));
  208.                     HPurge (Handle(pathRsrc));
  209.                 END;
  210.             DisposHandle (Handle (storHdl));
  211.         END;
  212.  
  213.     END;
  214.  
  215.  
  216. END.
  217.